﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace API.Models.Repository
{
    public class INVOICES_Repository : GenericRepository<PartnerDbContext, WH_INVOICES>
    {
        public override void Add(WH_INVOICES entity)
        {
            this.InsertOrUpdate(entity);
        }

        public override IQueryable<WH_INVOICES> Find(System.Linq.Expressions.Expression<Func<WH_INVOICES, bool>> predicate)
        {
            /// Получить данные
            IQueryable<WH_INVOICES> query = _entities.WH_INVOICES;
                //.Include("COMPANY")
                //.Include("CUSTOMER")
                //.Include("LOCATION")
                //.Include("LINES")
                //.Include("LINES.ITEM");

                //.Include("CUSTOMER.LOCATIONS")
                //.Include("COMPANY_MAPPED")
                //.Include("CUSTOMER_MAPPED")
                //.Include("LOCATION_MAPPED")


            /// Фильтрация по заданному условию
            if (predicate != null)
                query = query.Where(predicate);

            if (session != null)
                query = query
                    .Where(r => 
                        r.COMPANY_GUID == session.COMPANY_GUID || 
                        r.CUSTOMER_MAPPED_GUID == session.COMPANY_GUID);

            return query.AsQueryable();
        }
    }
}